package com.engine.core.gen;

import com.engine.core.interceptor.Command;
import com.engine.core.interceptor.JdbcCommandContext;
import com.engine.core.util.Response;
import com.engine.system.User;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public abstract class DbPlayload<T extends DbPlayload> implements Command<Response, JdbcCommandContext> {

    protected User user;

    /**
     * 查询列参数
     */
    protected String queryColumns;

    /**
     * 查询条件部分
     */
    protected String queryWhere;

    /**
     * 查询表、或者其他视图部分
     */
    protected  String queryFrom;

    protected  String queryOrderBy;

    protected  String queryGroupBy;

    protected  String queryHaving;

    protected boolean isMapParam;
    protected  String querySql;
    protected boolean queryParamsForce;
    protected boolean fethchResult=true;

    protected String bodyContent;


    protected boolean  isConvertParam=true;

    protected Map<String,Object> paramsMap=new LinkedHashMap<>();

    //替换sql中的
    protected Map<String,String> addReplace=new LinkedHashMap<>();



    protected String table;
    protected int dataType;
    protected  Enum operType;
    protected  List<Map<String,Object>> listdata;
    protected Map<String,Object> mapdata;
    protected Map<String,String> updateCothers=new LinkedHashMap<String,String>();
    protected List<String> updateColumns=new ArrayList<>();
    protected List<String> whereColumns=new ArrayList<>();

    protected boolean isQuery;

    public DbPlayload(boolean isQuery) {
        this.isQuery = isQuery;
    }

    public DbPlayload(boolean isQuery,User user) {
        this.isQuery = isQuery;
        this.user=user;
    }

    public abstract Map<String,Object> getParams();

    public T putAll(Map<String,Object> map) throws Exception {
          this.paramsMap.putAll(map);
          return (T)this;
    }

    public T bodyContent(String bodyContent) {
        this.bodyContent = bodyContent;
        return (T)this;
    }

    public T fethchResult(boolean fethchResult) {
        this.fethchResult = fethchResult;
        return (T)this;
    }

    public T addReplacement(String replacement,String replaceValue,Map<String,Object> replaceParams){
        this.addReplace.put(replacement,replaceValue);
        this.paramsMap.putAll(replaceParams);
        return (T)this;
    }
}
